#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
#define endl '\n'
const int N = 110;
const int MOD = 1e9 + 7;
LL a[N][N], ret[N][N], tmp[N][N];
LL n, k;

class mat
{
    public:
    LL a[N][N];
    mat()
    {
        memset(a, 0, sizeof a);
    }
    mat operator* (const mat& B) const
    {
        mat C;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                for(int k = 1; k <= n; k++)
                {
                    C.a[i][j] = (C.a[i][j] + (a[i][k] * B.a[k][j])) % MOD;
                }
            }
        }
        return C;
    }

}A, RET;

void mat_qpow(LL n, LL k)
{
    for(int i = 1; i <= n; i++) RET.a[i][i] = 1;
    while(k)
    {
        if(k & 1) RET = RET * A;
        k >>= 1;
        A = A * A;
    }
}

void solve() 
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> A.a[i][j];

    mat_qpow(n, k);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cout << RET.a[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
	// cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}